<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class PlayerIndexResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        $info = (new PlayerResource($this))->toArray($request);
        $season = (new SeasonResource($this->season))->toArray($request);
        $chapter = (new ChapterResource($this->chapter))->toArray($request);
        $sponsors = SponsorResource::collection($this->chapter->sponsors()->ordered()->get());
        $config = $this->season->getConfig([
            'allow_custom_amount',
            'amount_max',
            'amount_min',
            'amount_tips',
            'show_captcha',
            'show_comment',
            'show_comment_log',
            'show_like',
            'show_like_log',
            'show_rank_time',
            'show_support',
            'show_support_log',
            'first_show_before',
        ]);

        return [
            'info' => $info,
            'season' => $season,
            'chapter' => $chapter,
            'sponsors' => $sponsors,
            'config' => $config,
        ];
    }
}
